home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing;
-
- import com.sun.java.accessibility.AccessibleContext;
- import com.sun.java.swing.event.EventListenerList;
- import com.sun.java.swing.text.Document;
- import com.sun.java.swing.text.JTextComponent;
- import com.sun.java.swing.text.PlainDocument;
- import com.sun.java.swing.text.TextAction;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Rectangle;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
-
- public class JTextField extends JTextComponent implements SwingConstants {
- public static final String notifyAction = "notify-field-accept";
- private BoundedRangeModel visibility;
- private int horizontalAlignment;
- private int columns;
- private int columnWidth;
- private String command;
- private static final Action[] defaultActions = new Action[]{new NotifyAction()};
- static Class class$java$awt$event$ActionListener;
-
- public JTextField() {
- this((Document)null, (String)null, 0);
- }
-
- public JTextField(int columns) {
- this((Document)null, (String)null, columns);
- }
-
- public JTextField(Document doc, String text, int columns) {
- this.horizontalAlignment = 2;
- if (columns < 0) {
- throw new IllegalArgumentException("columns less than zero.");
- } else {
- this.visibility = new DefaultBoundedRangeModel();
- this.visibility.addChangeListener(new ScrollRepainter(this));
- this.columns = columns;
- if (doc == null) {
- doc = this.createDefaultModel();
- }
-
- ((JTextComponent)this).setDocument(doc);
- if (text != null) {
- ((JTextComponent)this).setText(text);
- }
-
- }
- }
-
- public JTextField(String text) {
- this((Document)null, text, 0);
- }
-
- public JTextField(String text, int columns) {
- this((Document)null, text, columns);
- }
-
- public synchronized void addActionListener(ActionListener l) {
- EventListenerList var10000 = super.listenerList;
- Class var10001 = class$java$awt$event$ActionListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("java.awt.event.ActionListener");
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
-
- class$java$awt$event$ActionListener = var10001;
- }
-
- var10000.add(var10001, l);
- }
-
- protected Document createDefaultModel() {
- return new PlainDocument();
- }
-
- protected void fireActionPerformed() {
- Object[] listeners = super.listenerList.getListenerList();
- ActionEvent e = new ActionEvent(this, 1001, this.command != null ? this.command : ((JTextComponent)this).getText());
-
- for(int i = listeners.length - 2; i >= 0; i -= 2) {
- Object var10000 = listeners[i];
- Class var10001 = class$java$awt$event$ActionListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("java.awt.event.ActionListener");
- } catch (ClassNotFoundException var4) {
- throw new NoClassDefFoundError(((Throwable)var4).getMessage());
- }
-
- class$java$awt$event$ActionListener = var10001;
- }
-
- if (var10000 == var10001) {
- ((ActionListener)listeners[i + 1]).actionPerformed(e);
- }
- }
-
- }
-
- public AccessibleContext getAccessibleContext() {
- if (super.accessibleContext == null) {
- super.accessibleContext = new AccessibleJTextField(this);
- }
-
- return super.accessibleContext;
- }
-
- public Action[] getActions() {
- return TextAction.augmentList(super.getActions(), defaultActions);
- }
-
- public int getColumns() {
- return this.columns;
- }
-
- protected int getColumnWidth() {
- if (this.columnWidth == 0) {
- FontMetrics metrics = ((Component)this).getFontMetrics(((Component)this).getFont());
- this.columnWidth = metrics.charWidth('m');
- }
-
- return this.columnWidth;
- }
-
- public int getHorizontalAlignment() {
- return this.horizontalAlignment;
- }
-
- public BoundedRangeModel getHorizontalVisibility() {
- return this.visibility;
- }
-
- public Dimension getMinimumSize() {
- return this.getPreferredSize();
- }
-
- public Dimension getPreferredSize() {
- synchronized(((Component)this).getTreeLock()) {
- Dimension size = super.getPreferredSize();
- if (this.columns != 0) {
- size.width = this.columns * this.getColumnWidth();
- }
-
- return size;
- }
- }
-
- public int getScrollOffset() {
- return this.visibility.getValue();
- }
-
- public String getUIClassID() {
- return "TextFieldUI";
- }
-
- public boolean isValidateRoot() {
- return true;
- }
-
- protected String paramString() {
- return super.paramString() + ",columns=" + this.columns + ",command=" + this.command;
- }
-
- public void postActionEvent() {
- this.fireActionPerformed();
- }
-
- public synchronized void removeActionListener(ActionListener l) {
- EventListenerList var10000 = super.listenerList;
- Class var10001 = class$java$awt$event$ActionListener;
- if (var10001 == null) {
- try {
- var10001 = Class.forName("java.awt.event.ActionListener");
- } catch (ClassNotFoundException var2) {
- throw new NoClassDefFoundError(((Throwable)var2).getMessage());
- }
-
- class$java$awt$event$ActionListener = var10001;
- }
-
- var10000.remove(var10001, l);
- }
-
- public void scrollRectToVisible(Rectangle r) {
- int x = r.x + this.visibility.getValue();
- if (x < this.visibility.getValue()) {
- this.visibility.setValue(x - 2);
- } else if (x > this.visibility.getValue() + this.visibility.getExtent()) {
- this.visibility.setValue(x - this.visibility.getExtent() + 2);
- }
-
- }
-
- public void setActionCommand(String command) {
- this.command = command;
- }
-
- public void setColumns(int columns) {
- int oldVal = this.columns;
- if (columns < 0) {
- throw new IllegalArgumentException("columns less than zero.");
- } else {
- if (columns != oldVal) {
- this.columns = columns;
- ((Container)this).invalidate();
- }
-
- }
- }
-
- public void setFont(Font f) {
- super.setFont(f);
- this.columnWidth = 0;
- ((JComponent)this).revalidate();
- }
-
- public void setHorizontalAlignment(int alignment) {
- if (alignment != this.horizontalAlignment) {
- int oldValue = this.horizontalAlignment;
- if (alignment != 2 && alignment != 0 && alignment != 4) {
- throw new IllegalArgumentException("horizontalAlignment");
- } else {
- this.horizontalAlignment = alignment;
- ((JComponent)this).firePropertyChange("horizontalAlignment", oldValue, this.horizontalAlignment);
- ((Container)this).invalidate();
- ((Component)this).repaint();
- }
- }
- }
-
- public void setScrollOffset(int scrollOffset) {
- this.visibility.setValue(scrollOffset);
- }
- }
-